<template>
  <!--    查询栏目-->
    <el-card style="margin: 20px;heignt:70px;">
        <el-form :inline="true" style="margin-top: 10px;">
            <el-form-item style="width: 290px;">
                <el-input placeholder="请输入订单号" v-model="selectData.orderNo" style="margin-left:30px;"></el-input>
            </el-form-item>
            <el-form-item label="车辆状态" style="width: 290px;margin-left: 30px;">
                <el-select placeholder="请选择车辆状态" v-model="selectData.orderStatus">
                    <el-option label="预约中" value="1"></el-option>
                    <el-option label="租贷中" value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="selectOrderList">查询</el-button>
                <el-button type="primary" @click="resetSearch">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
  <!--    显示表格信息-->
    <el-card style="margin: 20px;">
        <el-table :data="checlistkArr">
            <el-table-column prop="orderNo" label="订单编号" align="center"></el-table-column>
            <el-table-column prop="customerId" label="客户ID"  align="center"></el-table-column>
            <el-table-column prop="orderStatus" label="订单状态"  align="center" :formatter="orderStatusFormatter"></el-table-column>
            <el-table-column label="操作" align="center">
                <template #default="scope">
                    <el-button link type="primary" size="small" @click="dialogVisable=true">新建检查单</el-button>
                    <el-button link type="primary" size="small" @click="delPendingList(scope.row.orderNo)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </el-card>
<!--    新建检查单弹窗-->
    <el-dialog :title="dialogTitle" v-model="dialogVisable" :before-close="handleClose"
               style="width:1000px;padding:40px;">
        <el-form label-width="80px" label-position="top">
                <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item label="用户ID">
                            <el-input type="number" placeholder="用户ID" v-model="selectData.customerId" aria-required="true" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="车辆ID">
                            <el-input type="number" placeholder="请输入车辆ID" v-model="selectData.vehicleId" aria-required="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item label="租车订单ID">
                            <el-input type="text" placeholder="请输入租车订单ID" v-model="selectData.rentalOrderId" aria-required="true"></el-input>
                        </el-form-item>
                    </el-col>
                <el-col :span="12">
                    <el-form-item label="发动机状况">
                        <el-input type="text" placeholder="请输入发动机状况" v-model="selectData.engineCondition" aria-required="true"></el-input>
                    </el-form-item>
                </el-col>
                </el-row>
            <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item label="外观状况">
                            <el-input type="text" placeholder="请输入外观状况" v-model="selectData.exteriorCondition" aria-required="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="内部设备">
                            <el-input type="text" placeholder="请输入内部设备" v-model="selectData.interiorEquipment" aria-required="true" ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            <el-row :gutter="10">
                <el-col :span="12">
                    <el-form-item label="灯光状况">
                        <el-input type="text" placeholder="请输入灯光状况" v-model="selectData.lightCondition" aria-required="true"></el-input>
                    </el-form-item>
                </el-col>
                    <el-col :span="12">
                        <el-form-item label="轮胎状况">
                            <el-input type="text" placeholder="请输入轮胎状况" v-model="selectData.tireCondition" aria-required="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            <el-row :gutter="10">

                    <el-col :span="12">
                        <el-form-item label="检查结果">
                            <el-input type="text" placeholder="请输入检查结果" v-model="selectData.checkResult" aria-required="true"></el-input>
                        </el-form-item>
                    </el-col>
                <el-col :span="12">
                    <el-form-item label="备注">
                        <el-input type="text" v-model="selectData.remaker"></el-input>
                    </el-form-item>
                </el-col>
                </el-row>
            <el-row :gutter="10">

                    <el-col :span="12">
                        <el-form-item label="检查时间" aria-required="true">
                            <el-date-picker type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                                            v-model="selectData.checkTime"/>
                        </el-form-item>
                    </el-col>
                </el-row>
        </el-form>
        <template #footer>
            <el-button @click="handleClose">取消</el-button>
            <el-button type="primary" @click="saveCheckList">保存</el-button>
        </template>
    </el-dialog>
</template>

<script setup>

import {onMounted, ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";


const  dialogTitle='新建检查单';
const dialogVisable=ref(false);
const checlistkArr=ref([]);
const  selectData=ref(
    {
        orderNo: '',
        orderStatus: '',
        vehicleId:'',
        customerId:'',
        exteriorCondition:'',
        interiorEquipment:'',
        engineCondition:'',
        tireCondition:'',
        lightCondition:'',
        checkResult:'',
        remaker:'',
        checkTime:'',
    }
);
// const selectData=ref({
//     vehicleId:'',
//     userId:'',
//     rentalOrderId:'',
//     exteriorCondition:'',
//     interiorEquipment:'',
//     engineCondition:'',
//     tireCondition:'',
//     lightCondition:'',
//     checkResult:'',
//     remaker:'',
//     checkTime:'',
// })

//关闭弹窗
const  handleClose=()=>{
    if (confirm("确定关闭窗口吗？")){
        dialogVisable.value=false;
        selectData.value={};
    }
}
//查询待检测订单
const  selectOrderList=()=>{
   let data=qs.stringify(selectData.value);
   axios.get(BASE_URL+'/checklist/pending/select?'+ data)
       .then((response)=>{
           if (response.data.code==2000){
               checlistkArr.value=response.data.data;
               ElMessage.success('操作成功');
           }else {
               ElMessage.error('操作失败');
           }

       })


}
//重置
const resetSearch = () => {
   selectData.value={};
   selectOrderList();
}
//页面加载
onMounted(() => {
selectOrderList();
})
//删除
const delPendingList=(orderNo)=>{
    console.log(orderNo);
    axios.post(BASE_URL+'/checklist/pending/delete/'+orderNo)
        .then((response)=>{
            if (response.data.code==2000){
                ElMessage.success('删除成功');
                selectOrderList();
            }else {
                ElMessage.error('操作失败');
            }

        })
}
//订单状态转换
const orderStatusFormatter=(row,column,cellValue,index)=>{
    if (cellValue=="CREATE"){
        return '订单创建';
    }else if (cellValue=="ORDER"){
        return '预约中';
    }else if (cellValue=="RENT"){
        return '租贷中';
    }else if (cellValue=="CANCEL"){
        return '取消';
    }else if (cellValue=="FINISH"){
        return '完成';
    }
};
//新建保存
const saveCheckList=()=>{
    let data=qs.stringify(selectData.value);
    axios.post(BASE_URL+'/checklist/completed/insert?'+data)
        .then((response)=>{
            if (response.data.code==2000){
                ElMessage.success('新建成功');
            }else {
                ElMessage.error('操作失败');
            }
        })
    dialogVisable.value=false;
}
</script>

<style scoped>

</style>